package com.xmzs.midjourney.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;

import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import com.xmzs.common.web.core.BaseController;
import com.xmzs.common.mybatis.core.page.PageQuery;
import com.xmzs.common.core.domain.R;
import com.xmzs.common.core.validate.AddGroup;
import com.xmzs.common.core.validate.EditGroup;

import com.xmzs.midjourney.domain.vo.MjRoomVo;
import com.xmzs.midjourney.domain.bo.MjRoomBo;
import com.xmzs.midjourney.service.IMjRoomService;
import com.xmzs.common.mybatis.core.page.TableDataInfo;

/**
 * MJ创作会话
 *
 * @author lixg
 * @date 2023-08-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/midjourney/mjroom")
public class MjRoomController extends BaseController {

    private final IMjRoomService mjRoomService;

    /**
     * 查询MJ创作会话列表
     */
    @SaCheckPermission("midjourney:mjroom:list")
    @GetMapping("/list")
    public TableDataInfo<MjRoomVo> list(MjRoomBo bo, PageQuery pageQuery) {
        return mjRoomService.queryPageList(bo, pageQuery);
    }



    /**
     * 获取MJ创作会话详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("midjourney:mjroom:query")
    @GetMapping("/{id}")
    public R<MjRoomVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(mjRoomService.queryById(id));
    }

    /**
     * 新增MJ创作会话
     */
    @SaCheckPermission("midjourney:mjroom:add")
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MjRoomBo bo) {
        return toAjax(mjRoomService.insertByBo(bo));
    }

    /**
     * 修改MJ创作会话
     */
    @SaCheckPermission("midjourney:mjroom:edit")
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MjRoomBo bo) {
        return toAjax(mjRoomService.updateByBo(bo));
    }

    /**
     * 删除MJ创作会话
     *
     * @param ids 主键串
     */
    @SaCheckPermission("midjourney:mjroom:remove")
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(mjRoomService.deleteWithValidByIds(List.of(ids), true));
    }
}
